package com.mxchip.livestar.ui.call

import android.util.Log
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.mxchip.livestar.utils.MyLog
import com.videohigh.graham.TermVideoDevice

object ScreenRepository {


    private val mStreamingAVDevices = MutableLiveData<Set<TermVideoDevice>>(linkedSetOf())


    fun addStreamingAVDevice(device: TermVideoDevice) {
        val list = mStreamingAVDevices.value

        Log.e("ScreenRepository", "addStreamingAVDevice before list: $list")

        if (list is LinkedHashSet) {
            list.add(device)
        }

        Log.e("ScreenRepository", "addStreamingAVDevice after list: $list")
        mStreamingAVDevices.value = list
    }

    fun removeStreamingAVDevice(device: TermVideoDevice) {

        val list = mStreamingAVDevices.value

        Log.e("ScreenRepository", "removeStreamingAVDevice before list: $list")

        if (list is LinkedHashSet) {
            list.removeIf {
                device == it
            }
        }

        MyLog.logD(MyLog.STREAMING_AV_DEVICE_MODEL,"ScreenRepository::removeStreamingAVDevice $list")

        mStreamingAVDevices.value = list
    }
    val streamingAVDevices: LiveData<Set<TermVideoDevice>>
        get() = mStreamingAVDevices

}